// - 封装一个函数，传入一个格林威治时间，返回一个北京标准时间格式：2021-11-01 05:01:01 
function formatDate(date) {
  function fill(num) {
    return num < 10 ? '0' + num : num;
  }
  let year = date.getFullYear();
  let month = date.getMonth() + 1;
  let day = date.getDate();
  let hour = date.getHours();
  let min = date.getMinutes();
  let sec = date.getSeconds();
  month = fill(month);
  day = fill(day);
  hour = fill(hour);
  min = fill(min);
  sec = fill(sec);
  return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
}

/**
 * 判断是不是今天
 * @param {str} timeStr 时间
 */
function isTody(timeStr) {
  let date1 = new Date();
  let date2 = new Date(timeStr);
  if (date1.getFullYear() === date2.getFullYear() &&
    date1.getMonth() === date2.getMonth() &&
    date1.getDate() === date2.getDate()) {
    return true;
  }
  return false;
}

module.exports = {
  formatDate: formatDate,
  isTody: isTody
}